﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;
using System.Drawing;
using System.Windows.Forms;

namespace TERP.WaterClient.Common
{
    public class EmbeddedRes
    {
        private static EmbeddedRes _instance;
        public static EmbeddedRes Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new EmbeddedRes();
                return _instance;
            }
        }

        public EmbeddedRes()
        {
            InitImageList();
        }

        private ImageList _imgListEditStatus = new ImageList();
        public ImageList ImageListEditStatus
        {
            get
            {
                return _imgListEditStatus;
            }
        }

		private Bitmap _bmpLogo = null;
		public Bitmap BimapLogo {
			get { return _bmpLogo; }
		}

        private Icon _appIcon = null;
        public Icon AppIcon
        {
            get { return _appIcon; }
        }

        //private Stream _imageStream = null;
        private const string NAME_SPACE_EMBEDDED_RES = "TERP.WaterClient.Images";

        private void InitImageList()
        {
            this._imgListEditStatus.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
            this._imgListEditStatus.ImageSize = new System.Drawing.Size(16, 16);
            this._imgListEditStatus.TransparentColor = System.Drawing.Color.Transparent;
            //
            //ResourceManager rm = new ResourceManager("myResources", Assembly.GetExecutingAssembly());
            //rm.GetObject("");
            Assembly _assembly;
            try
            {
                _assembly = Assembly.GetExecutingAssembly();
                //_imageStream = _assembly.GetManifestResourceStream(NAME_SPACE_EMBEDDED_RES+".status_delete.png");
                Bitmap bmpSttDelete = new Bitmap(
                    _assembly.GetManifestResourceStream(NAME_SPACE_EMBEDDED_RES + ".status_delete.png"));
                Bitmap bmpSttEdit = new Bitmap(
                    _assembly.GetManifestResourceStream(NAME_SPACE_EMBEDDED_RES + ".status_edit.png"));
                Bitmap bmpTransparent = new Bitmap(
                    _assembly.GetManifestResourceStream(NAME_SPACE_EMBEDDED_RES + ".transparent.png"));
				Bitmap bmpNew = new Bitmap(
					_assembly.GetManifestResourceStream(NAME_SPACE_EMBEDDED_RES + ".status_new.png"));
                _appIcon = new Icon(
                    _assembly.GetManifestResourceStream(NAME_SPACE_EMBEDDED_RES + ".app_icon.ico"));
                //
                this._imgListEditStatus.Images.Add("0", bmpTransparent);
                this._imgListEditStatus.Images.Add("1", bmpSttEdit);
                this._imgListEditStatus.Images.Add("2", bmpSttDelete);
				this._imgListEditStatus.Images.Add("3", bmpNew);
				//
				_bmpLogo = new Bitmap(
                    _assembly.GetManifestResourceStream(NAME_SPACE_EMBEDDED_RES + ".car.png"));
            }
            catch (Exception ex)
            {
                Util.WriteLine("Error access resources:" + ex.Message);
            }
        }
    }
}